﻿$(function () {
    var $sidebar = $("#sidebar");
    var $main = $('#main-content');
    var $breadNav = $('#breadNav');

    $('#nav-accordion').dcAccordion({
        autoExpand: true
    });

    // custom scrollbar
    if (!$.browser.versions.ios) $("#sidebar").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '', scrollspeed: 60 });

    $("#gotoTop").on('click', function (e) {
        e.preventDefault();
        $('#main-content, .content-body, body').animate({
            scrollTop: 0
        }, 200);
    });
    $('[role="tooltip"]').lgbTooltip();

    $sidebar.on('click', 'a.dcjq-parent', function () {
        var o = ($(this).offset());
        diff = 110 - o.top;
        if (diff > 0)
            $sidebar.scrollTo("-=" + Math.abs(diff), 500);
        else
            $sidebar.scrollTo("+=" + Math.abs(diff), 500);
    });

    $('.sidebar-toggle-box').on('click', function () {
        if ($sidebar.is(":visible") === true) {
            $sidebar.hide();
            $main.addClass('closed').removeClass('open');
        } else {
            $sidebar.show();
            $main.addClass('open').removeClass('closed');
        }
    });

    var arch = $('#nav-accordion').find('a.active').last();
    var top = (arch.offset() || { top: 0 }).top;
    if (top > 0) {
        var middle = $('header').outerHeight() + $sidebar.outerHeight() / 2;
        if (top > middle) $sidebar.animate({ scrollTop: top + arch.outerHeight() / 2 - middle }, 500);
    }
});